package ren.kane.asdppp.transaction.cost;

import ren.kane.asdppp.Employee;
import ren.kane.asdppp.PayrollDatabase;
import ren.kane.asdppp.transaction.Transaction;
import ren.kane.asdppp.classification.HourlyClassification;

import java.time.LocalDate;

/**
 * @author renrk(1275) on 2019-04-15 8:04 PM
 **/
public class TimeCardTransaction implements Transaction {

    private LocalDate date;

    private double hours;

    private int empId;

    public TimeCardTransaction() {
    }

    public TimeCardTransaction(LocalDate date, double hours, int empId) {
        this.date = date;
        this.hours = hours;
        this.empId = empId;
    }

    @Override
    public void execute() {
        Employee employee = PayrollDatabase.getEmployee(empId);
        if (null != employee) {
            HourlyClassification hourlyClassification = (HourlyClassification) employee.getPaymentClassification();
            if (null != hourlyClassification) {
                hourlyClassification.addTimeCard(new TimeCard(date, hours));
            }
        }
    }
}
